from typing import Any, Iterable

from zkl_pyutils_registries import ComposedMatcher, ListRegistry, MutableCallablesRegistry, TolerantMatcher

from .convertor import Convertor
from .tag import Tag


class ConvertorRegistry(MutableCallablesRegistry[Any, Any, Convertor]):
    def __init__(self, tags: Iterable[Tag[Any, Any, Any]] = ()):
        matcher = ComposedMatcher[Tag, Any, Any, Convertor]({
            tag: TolerantMatcher(tag.matcher) for tag in tags if tag.matcher is not None})
        super().__init__(MutableCallablesRegistry[Any, Any, Convertor](ListRegistry(matcher)))
        self._matcher = matcher

    @property
    def matcher(self) -> ComposedMatcher[Tag, Any, Any, Convertor]:
        return self._matcher
